﻿using System;

namespace QDT.Core.Projects
{
    public class RepaymentStage : IComparable {
        
        public RepaymentStage(int stage,DateTime time,decimal interest,decimal principal,string remark="") {
            Stage = stage;
            Time = time;
            ActualTime = time;
            Interest = interest;
            Principal = principal;
            Remark = remark;
        }

        /// <summary>
        /// 阶段，期次
        /// </summary>
        public int Stage { get; set; }

        /// <summary>
        /// 是否偿还
        /// </summary>
        public bool IsRepay { get; set; }

        /// <summary>
        /// 还款时间
        /// </summary>
        public DateTime Time { get; set; }

        /// <summary>
        /// 实际还款的时间
        /// </summary>
        public DateTime ActualTime { get; set; }

        /// <summary>
        /// 偿还利息部分
        /// </summary>
        public decimal Interest { get; set; }

        /// <summary>
        /// 偿还本金部分
        /// </summary>
        public decimal Principal { get; set; }

        /// <summary>
        /// 偿还总额(本金+利息)
        /// </summary>
        public decimal Ammount { get { return Interest + Principal; } }

        /// <summary>
        /// 备注
        /// </summary>
        public string Remark { get; set; }

        /// <summary>
        /// 偿还类型：1是利息 2是本金  3是本金和利息
        /// </summary>
        public int RepayType { get; set; }

        /// <summary>
        /// 状态
        /// </summary>
        public string Status {
            get {
                if (IsRepay) {

                    if (ActualTime.Date > Time.Date) return "逾期还款";

                    return ActualTime < Time ? "提前还款" : "正常还款";
                }
                return "未偿还";
            }
        }

        /// <summary>
        /// 是否是最后一期
        /// </summary>
        public bool IsLast { get; set; }

        #region Implementation of IComparable

        public int CompareTo(object obj) {
            var x = obj as RepaymentStage;

            if (x == null) throw new ArgumentException("obj 不具有与此实例相同的类型.");

            if (Stage < x.Stage) return -1;

            if (Stage > x.Stage) return 1;

            return 0;
        }

        #endregion
    }
}